﻿using UnityEngine;
using System.Collections;


public class RightButtons : MonoBehaviour
{
    
    public GameObject RightWdw;
    public int FirstDept;

    bool Activate = false;

    bool m_bIsOver;
    float m_fHoverSpeed;

    void Start()
    {
        m_fHoverSpeed = 250f * Time.fixedDeltaTime;
    }

    void OnEnable()
    {
        transform.localPosition = new Vector3(19, transform.localPosition.y);
        m_bIsOver = false;
    }

    public void OnClick()
    {
        if (!GameObject.Find("RightWdw").GetComponent<RightWdwMgr>().m_bSelectUnitPage)
        {
            if (!Activate)
            {
                transform.localPosition = new Vector3(105, transform.localPosition.y);
                RightWdw.SetActive(true);
                gameObject.GetComponent<UISprite>().depth = -1;
                Activate = true;

                gameObject.SetActive(false);
            }
        }
        else
        {
            GameObject WarnMsg = Instantiate(Resources.Load("Prefaps/UI/StaticUI/Warn/WarnMessageLabel") as GameObject) as GameObject;
            WarnMsg.transform.parent = GameObject.Find("UnitPanel").transform;
            WarnMsg.GetComponent<UILabel>().text = GameObject.Find("SelectUnitExplain").GetComponent<UILabel>().text;
        }
        

    }

    void Update()
    {
        if (m_bIsOver)
        {
            if (transform.localPosition.x > 19)
                transform.localPosition = new Vector3(transform.localPosition.x - m_fHoverSpeed, transform.localPosition.y);
            else
                transform.localPosition = new Vector3(19, transform.localPosition.y);
        }
        else
        {
            if (transform.localPosition.x < 47.5)
                transform.localPosition = new Vector3(transform.localPosition.x + m_fHoverSpeed, transform.localPosition.y);
            else
                transform.localPosition = new Vector3(47.5f, transform.localPosition.y);
        }

        switch (FirstDept)
        {
            case 1:
                if (Input.GetKeyUp(KeyCode.F1))
                    OnClick();
                break;

            case 2:
                if (Input.GetKeyUp(KeyCode.F2))
                    OnClick();
                break;

            case 3:
                if (Input.GetKeyUp(KeyCode.F3))
                    OnClick();
                break;
        }
    }

    void OnHover(bool isOver)
    {
        if (isOver)
        {
            m_bIsOver = true;
            GameObject.Find("MainCamera").GetComponent<AudioSource>().PlayOneShot(Resources.Load<AudioClip>("Audio/PageTurn_0"));
        }
        else
            m_bIsOver = false;
    }

    public void WdwClose()
    {
        Activate = false;
        transform.localPosition = new Vector3(11.52f, transform.localPosition.y);
    }
}